package org.xmonkey.controller.extractor;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.xmonkey.Messages;

/**
 * This class represents a request whose aim is to start analyzing a project
 * @author jacopom
 *
 */
public final class ProjectAnalysisRequest extends ProjectRelatedJob {
	private IJobChangeListener listener;

	public ProjectAnalysisRequest(IProject project,IJobChangeListener listener) {
		super(Messages.ProjectAnalysisRequest_0, project);
		this.listener = listener;
		schedule();
	}
	
	private void analyze(IProject project, IJobChangeListener listener){
		// parse the project
		ASTProjectParser parser = new ASTProjectParser(project);
		// add listener
		parser.addJobChangeListener(listener);
		// schedule
		parser.schedule();
	}

	@Override
	protected IStatus run(IProgressMonitor monitor) {
		analyze(getProject(), listener);
		return Status.OK_STATUS;
	}

}
